<template>
	<view>
		<u-navbar title="设置" bgColor="rgba(255,255,255,0)"></u-navbar>
		<view class="u-flex u-flex-center" style="padding: 40rpx 0 120rpx 0;">
			<u-avatar size="132rpx" :src="user.wxpic" @click="setwxpic()"></u-avatar>
		</view>
		<view class="list">
			<view class="item" @click="setwxnc()">
				<view class="label">
					{{$z.$t("昵称")}}
				</view>
				<view class="value u-flex">
					{{ user.wxnc}}
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
			<!-- #ifndef APP-PLUS -->
			<view class="item noafter" @click="setutel()">
				<view class="label">
					{{$z.$t("手机号")}}
				</view>
				<view class="value u-flex">
					{{ user.utel}}
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>

			<!-- #endif -->
			<!-- #ifdef APP-PLUS -->
			<view class="item" @click="setutel()">
				<view class="label">
					{{$z.$t("手机号")}}
				</view>
				<view class="value u-flex">
					{{ user.utel}}
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
			<view class="item noafter" @click="changeLanguage">
				<view class="label">
					{{ $z.$t("切换语言")}}
				</view>
				<view class="value u-flex">
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
			<!-- #endif -->
			<!-- 	<view class="item">
				<view class="label">
					用户协议服务
				</view>
				<view class="value u-flex">

					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>

			<view class="item noafter">
				<view class="label">
					用户隐私政策
				</view>
				<view class="value u-flex">
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view> -->

		</view>
		<u-action-sheet :closeOnClickOverlay="true" @close="show = false" @select="selectClick" :actions="list1"
			:show="show"></u-action-sheet>
		<zmodal ref="zmodal"></zmodal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {},
				list1: [{
						name: 'English',
						color: this.$store.state.user.language === 'English' ? '#3b68f0' : '',
					},
					{
						name: '中文',
						color: this.$store.state.user.language === '中文' ? '#3b68f0' : '',
					}
				],
				show: false,
			}
		},
		onLoad() {
			this.init()
		},
		methods: {
			async init() {
				let user = await this.$store.dispatch("user/getuser", true);
				this.user = user;
			},
			setwxnc() {
				this.$refs.zmodal.init({
					showcancel: true,
					title: this.$z.$t("用户昵称"),
					type: "input",
					modalvalue: this.user.wxnc,
					confirm: async (config) => {
						await this.$z.request("/Uedt", {
							...this.user,
							wxnc: config.modalvalue
						})
						this.init()
					}
				})
			},
			async setwxpic() {
				let src = await this.$z.upimg();

				await this.$z.request("/Uedt", {
					...this.user,
					wxpic: src
				})
				this.init()
			},
			setutel() {
				this.$refs.zmodal.init({
					showcancel: true,
					title: this.$z.$t("手机号"),
					type: "input",
					modalvalue: this.user.utel,
					confirm: async (config) => {
						await this.$z.request("/Uedt", {
							...this.user,
							utel: config.modalvalue
						})
						this.init()
					}
				})
			},
			changeLanguage() {
				this.show = true
			},
			selectClick(item) {
				uni.setStorageSync('language', item.name)
				this.$store.commit('user/setLanguage', uni.getStorageSync('language'))
				if (uni.getStorageSync('utype') == 0) {
					uni.reLaunch({
						url: '/pages/index2/index2'
					});
				}
				if (uni.getStorageSync('utype') == 106) {
					uni.reLaunch({
						url: '/pages/index1/index1'
					});
				}
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: linear-gradient(#e2eef4, #f4f7f8);
		min-height: 100vh;
	}

	.list {
		background-color: #fff;

		.item {
			height: 100rpx;
			display: flex;
			align-items: center;
			position: relative;
			justify-content: space-between;
			padding: 0 36rpx 0 40rpx;

			&::after {
				content: "";
				position: absolute;
				height: 2rpx;
				background: $uni-border-color;
				left: 30rpx;
				right: 30rpx;
				bottom: 0;
			}

			.label {
				font-weight: bold;
			}


		}
	}

	.noafter {
		&::after {
			display: none;
		}
	}
</style>